from rest_framework import serializers

from cart.models import CartModel


class CartSerializer(serializers.ModelSerializer):
    courselist = serializers.SerializerMethodField(read_only=True)

    def get_courselist(self, obj):
        return {
            'id': obj.course.id,
            'c_name': obj.course.c_name,
            'price': obj.course.price,
            'discount': obj.course.discount,
            'cover': str(obj.course.cover),
            'level': obj.course.level
        }

    class Meta:
        model = CartModel
        fields = '__all__'
